const { defineConfig } = require('@vue/cli-service');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const cesiumSource = './node_modules/cesium/Source';

const prot = 80;

module.exports = defineConfig({
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [path.resolve(__dirname, './src/common/colors.less')],
    },
  },
  publicPath: process.env.VUE_APP_PRE_PATH,
  transpileDependencies: true,
  outputDir: 'dist',
  devServer: {
    port: prot, //端口号
    host: '0.0.0.0', // 主机名
    open: false,
    proxy: {
      // 文件上传代理
      // [process.env.VUE_APP_FILE_API]: {
      //   target: process.env.VUE_APP_FILE_SERVICE_URL,
      //   changeOrigin: true,
      //   pathRewrite: {
      //     ['^' + process.env.VUE_APP_FILE_API]: '/' + process.env.VUE_APP_FILE_API,
      //   },
      // },
      [process.env.VUE_APP_BASE_API]: {
        target: process.env.VUE_APP_SERVICE_URL,
        changeOrigin: true,
        pathRewrite: {
          // 248
          ['^' + process.env.VUE_APP_BASE_API]: '/' + process.env.VUE_APP_BASE_API,
          // 本地 170
          // ['^' + process.env.VUE_APP_BASE_API]: '/'
        },
      },
      [process.env.VUE_APP_MAP_API]: {
        target: process.env.VUE_APP_SERVICE_URL,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_MAP_API]: '/' + process.env.VUE_APP_MAP_API,
        },
      },
      'live': {
        target: process.env.VUE_APP_SERVICE_URL,
        changeOrigin: true,
        "pathRewrite": {
          "^/live": "live"
        }
      },
    },
    client: {
      overlay: false, // 编译错误时，取消全屏覆盖（建议关掉）
    },
  },
  transpileDependencies: [
    // 转换非es6语法插件
    '@riophae/vue-treeselect',
  ],
  configureWebpack: {
    resolve: {
      extensions: ['.js', '.vue', '.json', '.less'],
      alias: {
        '@': path.resolve('src'),
      },
    },
    module: {
      unknownContextRegExp: /^.\/.*$/,
      unknownContextCritical: false, // 6 不让webpack打印载入特定库时候的警告
    },
  },
  lintOnSave: false, // 关闭格式检查
  productionSourceMap: false, // 打包时不会生成 .map 文件
});
